# PATHS
BINPATH=./bin
OBJPATH=./obj
SRCPATH=./src
MEDIAPATH=../../media
TEMPPATH=../../temp
BOOKSPATH=../../books

# PARAMS
G711CODEC=pcm_alaw
G711BRATE=8000
#TO DISABLE PUTPUT MESSAGES: DBG=
DBG=-DDEBUG

# COMMANDS
DOXYGEN=doxygen
MKDIR=mkdir
CP=cp
RM=rm
CC=gcc

# FILES
WAVFILES:=OSR_uk_000_0020_8k.wav OSR_uk_000_0021_8k.wav OSR_uk_000_0022_8k.wav OSR_uk_000_0023_8k.wav OSR_uk_000_0024_8k.wav

.PHONY: all
all : embedder extracter message

.PHONY: message
message :
	@echo ""
	@echo "Be sure that the arq.h file is configured for compiling for the x86!!"
	@echo ""

.PHONY: embedder
embedder : $(OBJPATH) $(BINPATH) $(BINPATH)/embedder

.PHONY: extracter
extracter : $(OBJPATH) $(BINPATH) $(BINPATH)/extracter

.PHONY: test
test : $(WAVFILES)

$(BINPATH)/embedder : $(OBJPATH)/embedderMain.o $(OBJPATH)/wav.o $(OBJPATH)/dwt.o $(OBJPATH)/logarithmic.o $(OBJPATH)/synchronization.o $(OBJPATH)/watermarking.o $(OBJPATH)/dwt1d.o $(OBJPATH)/utility.o $(OBJPATH)/daubechies.o
	$(CC) $^ -o $@ -lm

$(BINPATH)/extracter : $(OBJPATH)/extracterMain.o $(OBJPATH)/wav.o $(OBJPATH)/dwt.o $(OBJPATH)/logarithmic.o $(OBJPATH)/synchronization.o $(OBJPATH)/watermarking.o $(OBJPATH)/dwt1d.o $(OBJPATH)/utility.o $(OBJPATH)/daubechies.o
	$(CC) $^ -o $@ -lm

$(WAVFILES) : embedder extracter $(TEMPPATH)
	@echo Test: $@
	$(BINPATH)/embedder $(MEDIAPATH)/$@ $(TEMPPATH)/EMB_$@
	$(BINPATH)/extracter $(TEMPPATH)/EMB_$@ -
	@echo ""
	@echo Test G711: $@
	$(BINPATH)/embedder $(MEDIAPATH)/$@ $(TEMPPATH)/$@
	ffmpeg -loglevel panic -y -i $(TEMPPATH)/$@ -acodec $(G711CODEC) -ar $(G711BRATE) $(TEMPPATH)/PCM_$@ >/dev/null 2>&1
	ffmpeg -loglevel panic -y -i $(TEMPPATH)/PCM_$@ -f s16le -acodec pcm_s16le $(TEMPPATH)/WAV_$@ >/dev/null 2>&1
	$(BINPATH)/extracter $(TEMPPATH)/WAV_$@ -
	@echo ""

$(TEMPPATH) :
	$(MKDIR) $(TEMPPATH)

$(OBJPATH) :
	$(MKDIR) $(OBJPATH)

$(BINPATH) :
	$(MKDIR) $(BINPATH)

$(OBJPATH)/embedderMain.o : $(SRCPATH)/embedderMain.c
	$(CC) -c $^ -o$@ $(DBG)

$(OBJPATH)/extracterMain.o : $(SRCPATH)/extracterMain.c
	$(CC) -c $^ -o $@ $(DBG)

$(OBJPATH)/wav.o :  $(SRCPATH)/wav.c
	$(CC) -c $^ -o $@ $(DBG)

$(OBJPATH)/dwt.o : $(SRCPATH)/dwt.c
	$(CC) -c $^ -o $@ 

$(OBJPATH)/watermarking.o : $(SRCPATH)/watermarking.c
	$(CC) -c $^ -o $@

$(OBJPATH)/synchronization.o : $(SRCPATH)/synchronization.c
	$(CC) -c $^ -o $@

$(OBJPATH)/logarithmic.o : $(SRCPATH)/logarithmic.c
	$(CC) -c $^ -o $@

#SWT OBJECTS COMPILATION
$(OBJPATH)/utility.o : $(SRCPATH)/utility.c
	$(CC) -c $^ -o $@

$(OBJPATH)/daubechies.o : $(SRCPATH)/daubechies.c
	$(CC) -c $^ -o $@

$(OBJPATH)/dwt1d.o : $(SRCPATH)/dwt1d.c
	$(CC) -c $^ -o $@

$(OBJPATH)/libswt.o :$(SRCPATH)/libswt.c
	$(CC) -c $^ -o $@

.PHONY: books
books :
	@$(CD) $(BOOKSPATH); $(DOXYGEN) ../work/DSP/config.doxygen
	@$(CD) ../books/latex; make pdf; $(CP) refman.pdf ../speechWatermarks.pdf;
	@echo "for pdf documentation run:\033[01;38;5;160m evince ../books/speechWatermarks.pdf\033[0m"
	@echo "for web documentation run:\033[01;38;5;160m firefox ../books/html/index.html\033[0m"

.PHONY: clean
clean :
	$(RM) -rf $(BOOKSPATH)/*
	$(RM) -rf $(OBJPATH)
	$(RM) -rf $(BINPATH)
	$(RM) -rf $(TEMPPATH)

.PHONY: help
help :
	cat readme.txt
